/*
 * @Author      : ZhouQiJun
 * @Date        : 2025-08-09 02:49:55
 * @LastEditors : ZhouQiJun
 * @LastEditTime: 2025-08-10 21:08:57
 * @Description : 初始化地图
 */
import { getGis, setGis } from '@ol/api'
import { type GisKey, KEY, Platform } from '@ol/define'
//import CesiumInit from '../platform/cesium/hooks/useCesium'
import { olInit } from '@ol/platform'
import { type IViewerOptions, type IViewerOptionsOl } from '@ol/types.d'
import { isNil } from 'es-toolkit'

export default function setupMap(
  container: HTMLElement | string,
  config: IViewerOptions, // | CesiumInitConfig,
  key: GisKey = KEY,
  platform: Platform = Platform.OL,
) {
  let gis = getGis(key)
  if (!isNil(gis)) {
    console.warn('The gis already created, you should not recreate again! mapKey: ', key)
    return gis
  }

  if (platform === Platform.CESIUM) {
    // TODO
    // return CesiumInit(container, key, config as CesiumInitConfig).then((gis) => setGis(key, gis))
  }
  gis = olInit(container, config as IViewerOptionsOl, key)
  setGis(key, gis)
  return gis
}
